﻿# coding: utf-8

import wx
import wx.lib.filebrowsebutton as filebrowse

class wxDialogTerrainCreate(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, title = TD.TERRAIN_CREATE)

        sizerRegionWidth = self.__CreateUIRegionWidth()
        sizerRegionLength = self.__CreateUIRegionLength()
        sizerShaderFile = self.__CreateUIShaderFile()
        sizerDefaultLayerFile = self.__CreateUIDefaultLayerFile()
        sizerOkCancel = self.__CreateUIOkCancel()
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizerRegionWidth, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, border = 10)
        sizer.Add(sizerRegionLength, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, border = 10)
        sizer.Add(sizerShaderFile, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, border = 10)
        sizer.Add(sizerDefaultLayerFile, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, border = 10)
        sizer.Add(sizerOkCancel, 0, wx.CENTER, border = 15)
        self.SetSizer(sizer)
        self.Fit()

    def __CreateUIRegionWidth(self):
        staticRegionWidth = wx.StaticText(self, wx.NewId(), TD.TERRAIN_WIDTH)
        self._editRegionWidth = wx.TextCtrl(self, wx.NewId())
        sizerRegionWidth = wx.BoxSizer(wx.HORIZONTAL)
        sizerRegionWidth.Add(staticRegionWidth, 0, wx.CENTER, border = 10)
        sizerRegionWidth.Add(self._editRegionWidth, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerRegionWidth
        
    def __CreateUIRegionLength(self):
        staticRegionHeight = wx.StaticText(self, wx.NewId(), TD.TERRAIN_LENGTH)
        self._editRegionLength = wx.TextCtrl(self, wx.NewId())
        sizerRegionLength = wx.BoxSizer(wx.HORIZONTAL)
        sizerRegionLength.Add(staticRegionHeight, 0, wx.CENTER, border = 10)
        sizerRegionLength.Add(self._editRegionLength, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerRegionLength
        
    def __CreateUIShaderFile(self):
        self._fbbShaderFile = filebrowse.FileBrowseButton(
            self, -1, labelText= TD.TERRAIN_SHADER_FILE,
            size = (500, -1),
            buttonText= TD.BUTTON_BROWSE, 
            changeCallback = self.__OnShaderFileChanged,
            startDirectory = GLOBAL_SETTING._workDir + GLOBAL_SETTING._terrainShaderFile,
            fileMask = '*.fx')
        
        if GLOBAL_SETTING._terrainShaderFile:
            self._fbbShaderFile.SetValue(GLOBAL_SETTING._workDir + GLOBAL_SETTING._terrainShaderFile)
            
        sizerShaderFile = wx.BoxSizer(wx.HORIZONTAL)
        sizerShaderFile.Add(self._fbbShaderFile, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerShaderFile
        
    def __CreateUIDefaultLayerFile(self):
        self._fbbDefaultLayerFile = filebrowse.FileBrowseButton(
            self, -1, labelText= TD.TERRAIN_DEFAULT_LAYER_FILE,
            size = (500, -1),
            buttonText= TD.BUTTON_BROWSE, 
            changeCallback = self.__OnDefaultLayerFileChanged,
            startDirectory = GLOBAL_SETTING._workDir + GLOBAL_SETTING._defaultTerrainLayer,
            fileMask = '*.dds')
        
        if GLOBAL_SETTING._defaultTerrainLayer:
            self._fbbDefaultLayerFile.SetValue(GLOBAL_SETTING._workDir + GLOBAL_SETTING._defaultTerrainLayer)
            
        sizerDefaultLayerFile = wx.BoxSizer(wx.HORIZONTAL)
        sizerDefaultLayerFile.Add(self._fbbDefaultLayerFile, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerDefaultLayerFile
                        
    def __CreateUIOkCancel(self):
        bnTerrainCreateOk = wx.Button(self, wx.ID_OK, TD.BUTTON_OK)
        bnTerrainCreateCancel = wx.Button(self, wx.ID_CANCEL, TD.BUTTON_CANCEL)
        sizerOkCancel = wx.BoxSizer(wx.HORIZONTAL)
        sizerOkCancel.Add(bnTerrainCreateOk, 0, wx.ALL, border = 15)
        sizerOkCancel.Add(bnTerrainCreateCancel, 0, wx.ALL, border = 15)
        return sizerOkCancel
        
    def __OnShaderFileChanged(self, e):
        v = self._fbbShaderFile.GetValue()
        GLOBAL_SETTING._terrainShaderFile = REMOVE_ROOT_PATH(v)
        
    def __OnDefaultLayerFileChanged(self, e):
        v = self._fbbDefaultLayerFile.GetValue()
        GLOBAL_SETTING._defaultTerrainLayer = REMOVE_ROOT_PATH(v)
        
    def GetWidth(self):
        return int(self._editRegionWidth.GetValue())
        
    def GetHeight(self):
        return int(self._editRegionLength.GetValue())
        
    def GetShaderFile(self):
        return REMOVE_ROOT_PATH(self._fbbShaderFile.GetValue())
        
    def GetDefaultLayerFile(self):
        return REMOVE_ROOT_PATH(self._fbbDefaultLayerFile.GetValue())
        
